<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace app\cpmjagent\controller\article;

/**
 * Description of Notices
 *
 * @author SoChishun
 */
class NoticesController extends \app\cpmjagent\controller\AppbaseController {
    public function noticeslist(){
        $list = \app\cpmjagent\model\NoticesModel::where([])->paginate(20);
        $firstRowId = ($list->getCurrentPage() - 1) * $list->listRows();
        return view('', ['list' => $list, 'firstRowId' => $firstRowId]);
    }

    public function noticesedit($id = 0) {
        if ($id) {
            $data = \app\cpmjagent\model\NoticesModel::get($id);
        } else {
            $data = null;
        }
        return view('', ['data' => $data]);
    }

    public function doNoticesEditSave($msg = '', $id = 0) {
        if (!xsfn_validate_string($msg, 0, 512)) {
            $this->error('内容无效!');
        }
        $mNotices = new \app\cpmjagent\model\NoticesModel();
        $data['msg'] = $msg;
        $data['type'] = 'notice';
        $data['version'] = date('YmdHis');
        if ($id) {
            $mNotices->save($data, ['id' => $id]);
        } else {
            $mNotices->save($data);
        }

        $this->success('保存成功!', '!window.parent.location.reload();', '', 1);
    }
    public function doNoticesDelete($id=''){
        if(!$id){
            return ['status'=>false,'info'=>'参数无效'];
        }
        \app\cpmjagent\model\NoticesModel::destroy($id);
        return ['status'=>true,'info'=>''];
    }
}
